<!DOCTYPE html>
<!--
 * Copyright (c) 2010 The Chromium Authors. All rights reserved.  Use of this
 * source code is governed by a BSD-style license that can be found in the
 * LICENSE file.
-->
<html>
  <head>
	<script>
		chrome.extension.onRequest.addListener(
		  function(request, sender, sendResponse) {
		    //console.log(sender.tab ?
			//			"from a content script:" + sender.tab.url :
			//			"from the extension");
		    // Create a simple text notification:
			if (request.type == 'getvars') {
			  var response = {};
			  response.chatNotification = localStorage.chatNotification;
			  response.desktopNotification = localStorage.desktopNotification;
			  response.checkArea = localStorage.checkArea;
			  sendResponse(response);
			}
			else if (request.type == 'email') {
			  if(localStorage.desktopNotification == "true" || !localStorage.desktopNotification) {
			    var notification = webkitNotifications.createNotification(
			      'icon48.png',  // icon url - can be relative
			      'You have ' + request.inboxCount + ' new mail!',  // notification title
			      ''  // notification body text
			    );
			    notification.show();
				var hideTime = parseInt(localStorage.hideTime);
				if(!hideTime) hideTime = 10;
			    setTimeout(function() {
			      notification.cancel();
			    }, hideTime * 1000);
			  }
			  if (localStorage.newMailSoundNotification == "true" || ! localStorage.newMailSoundNotification) {
			    var newMailAudio = document.getElementById('newMailAudio');
				newMailAudio.src = localStorage.newMailSound ? localStorage.newMailSound : "bell-transition.mp3";
				newMailAudio.play();
			  }
			}
			else if (request.type == 'chat') {
			  if(localStorage.desktopNotification == "true" || !localStorage.desktopNotification) {
			    var chatNotification = webkitNotifications.createNotification(
				  'icon48.png',  // icon url - can be relative
				  'You have a new Gtalk message!',  // notification title
				  ''  // notification body text
			    );
			    chatNotification.show();
			    var hideTime = parseInt(localStorage.hideTime);
				if(!hideTime) hideTime = 10;
			    setTimeout(function() {
			      chatNotification.cancel();
			    }, hideTime * 1000);
			  }
			}
		  }
		);
	</script>
  </head>
  <body>
    <audio id="newMailAudio">
		<source src="" type="audio/mpeg">
	</audio>
  </body>
</html>
